package com.beikai.mybatisplus.methods;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * Created with IntelliJ IDEA.
 * User: beikai
 * Date: 2019/6/17
 * Time: 16:14
 * Description:  自定义方法  继承 abstractMethod 类
 */
public class MyDelete extends AbstractMethod {
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass,
                                                 Class<?> modelClass,
                                                 TableInfo tableInfo) {
        /**
         * 执行sql,动态sql 参考类 sqlMethod
         */
        String sql = "delete from "+tableInfo.getTableName();
        /**
         * mapper 接口方法名 一致
         */
        String method = "myDelete";
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, mapperClass);
        // 添加 删除 方法
        return this.addDeleteMappedStatement(mapperClass,method,sqlSource);
    }
}
